package com.sky.service.impl;

import com.sky.entity.Note;
import com.sky.mapper.NoteMapper;
import com.sky.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteServiceImpl implements NoteService {
    @Autowired
    private NoteMapper noteMapper;

    @Override
    public List<Note> list() {
        return noteMapper.selectAll();
    }

    @Override
    public void add(Note note) {
        note.setTime(java.time.LocalDateTime.now());
        noteMapper.insert(note); // insert后note.id自动回填
    }

    @Override
    public void update(Note note) {
        note.setTime(java.time.LocalDateTime.now());
        noteMapper.update(note);
    }

    @Override
    public void delete(Long id) {
        noteMapper.delete(id);
    }

    @Override
    public Note getById(Long id) {
        return noteMapper.selectById(id);
    }
}
